<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
</head>

<body>

    <div id="app">
        <!--@keyup.enter 回车录入事件  -->
        <input type="text" @keyup="add" v-model="message">

        <ul>
            <li v-for="(item,index) in list">{{item}}</li>
        </ul>
        <hr>
        <!--@keyup 写入就生成  -->
        <!-- <input type="text" @keyup="add()" v-model="message">
     <button @click="add()" >添加</button>
     <ul>
        <li v-for="(item,index) in list">{{item}}</li>
     </ul>
     <hr> -->
        <!--@mouseout 写入就生成  -->
        <!-- <input type="text" @mouseout="add()" v-model="message">
     <button @click="add()" >添加</button>
     <ul>
        <li>{{message}}</li>
     </ul>-->
    </div>
</body>
<script>
    const app = new Vue({
        el: '#app',
        data: {
            message: "hello",
            list: [],
        },
        methods: {
            add(e) {
                if (e.key === 'Enter') {
                    this.list.push(this.message)
                }
                console.log(e)
            }
        }
    })
</script>

</html>